<?php
namespace app\zhongcan\controller;

use app\zhongcan\model\NavModel;
use cmf\controller\AdminBaseController;

class NavController extends AdminBaseController
{
    public function index()
    {
        $id= input('id');
        $where = [];
        if($id){
            $where[] = ['id','like',"%$id%"];
        }
        $data = NavModel::order('list_order','desc')
            ->where($where)
            ->paginate('2');;
        return $this->fetch('index',[
            'data' => $data
        ]);
    }

    public function add()
    {
        return $this->fetch('add');
    }

    public function addPost()
    {
        $data = input();
        $save = NavModel::create($data);
        if($save){
            $this->success('添加成功');
        }else{
            $this->error('添加失败');
        }
    }
    public function edit()
    {
        $id=input('id');
        $data = NavModel::find($id);
        return $this->fetch('edit',[
            'data' => $data
        ]);
    }
    public function editPost()
    {
        $data = input();
        $save = NavModel::update($data);
        if($save){
            $this->success('修改成功');
        }else{
            $this->error('修改失败');
        }
    }
    public function delete()
    {
        $id=input('id');
        $delete = NavModel::destroy($id);
        if($delete){
            $this->success('删除成功');
        }else{
            $this->error('删除失败');
        }
    }
    public function list_order()
    {
        $model= new NavModel();
        parent::listOrders($model);
        $this->success('排序成功');
    }
}
